
def test_palin(s):
    l = len(s)
    if l == 1:
        return True
    l >>= 1
    return s[:l] == ''.join(reversed(s[-l:]))

s = 0
for i in range(1000000):
    if test_palin(str(i)) and test_palin('{:b}'.format(i)):
        print i
        s += i
print 'sum: %d' % s